package com.ldkj.panzh.Enum;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 摄像头标识与IP映射枚举类
 */
public enum CameraIdentifierEnum {
    // 摄像头标识与IP的映射关系
    CAMERA_1("473d2c1bb14243669129ddf630605ebc", "192.168.31.6"),
    CAMERA_2("72338515701a496abcb173693def2861", "192.168.31.12"),
    CAMERA_3("ca5930b196344f0ba568c89d4d1bf664", "192.168.31.135"),
    CAMERA_4("6653c609b44f48b7ae0ac2eb6510f3c1", "192.168.31.131"),
    CAMERA_5("da55121974e842a6a3fe0fcf080e6f56", "192.168.31.28"),
    CAMERA_6("61675a3352354d4fac4fd0c003eae355", "192.168.31.120"),
    CAMERA_7("aaf54e477dae4b2aa895c8f49498b643", "192.168.34.98"),
    CAMERA_8("940f53e34fc447fbad341da46ff7933e", "192.168.31.132"),
    CAMERA_9("6abb3cc19d714c11a4406cdf72782d15", "192.168.31.121"),
    CAMERA_10("57cff97ee36b4542b40e681b0c913063", "192.168.31.3"),
    CAMERA_11("2322c38a566f4d16a139cb55f91ca98e", "192.168.31.17"),
    CAMERA_12("0a00888951064dbba0f3874489d1fa70", "192.168.31.22"),
    CAMERA_13("9228ffbe901f499a8923b4b77f5c8903", "192.168.31.154"),
    CAMERA_14("192.168.32.16", "192.168.32.16"),
    CAMERA_15("89c6a10ec00845989b101ba279897aec", "192.168.34.77"),
    CAMERA_16("65ba78a7effc498795bddfecaebcc8ff", "192.168.31.146"),
    CAMERA_17("a84f7587b02043d4bb812c713bea6b8f", "192.168.31.30"),
    CAMERA_18("a06157007ba946f5b40998e782cda4a3", "192.168.34.27"),
    CAMERA_19("a4b679b5a41a4310898cb74abd419e92", "192.168.34.69"),
    CAMERA_20("e9fe9c855244498ebdb72c3a57c2b4c8", "192.168.34.12"),
    CAMERA_21("aee6c51776b54b61a055d284a312d58b", "192.168.34.43"),
    CAMERA_22("e6ac398f901e4587b39181b63dd02b02", "192.168.34.2"),
    CAMERA_23("bd2ee9ae21dd418e96cf46d8f04aba26", "192.168.34.17");

    // 摄像头标识
    private final String identifier;
    // 摄像头IP
    private final String ip;

    // 缓存IP与标识的映射关系，提高查询效率
    private static final Map<String, String> IP_TO_IDENTIFIER_MAP = new HashMap<>();

    // 静态代码块初始化缓存
    static {
        for (CameraIdentifierEnum camera : values()) {
            IP_TO_IDENTIFIER_MAP.put(camera.ip, camera.identifier);
        }
    }

    // 构造方法
    CameraIdentifierEnum(String identifier, String ip) {
        this.identifier = identifier;
        this.ip = ip;
    }

    // 根据IP获取摄像头标识
    public static String getIdentifierByIp(String ip) {
        return IP_TO_IDENTIFIER_MAP.get(ip);
    }

    // 批量根据IP获取摄像头标识
    public static Map<String, String> getIdentifiersByIps(List<String> ips) {
        Map<String, String> result = new HashMap<>();
        if (ips == null || ips.size() == 0) {
            return result;
        }

        for (String ip : ips) {
            result.put(ip, getIdentifierByIp(ip));
        }
        return result;
    }

    // getter方法
    public String getIdentifier() {
        return identifier;
    }

    public String getIp() {
        return ip;
    }
}
